//
//  TeamModel.swift
//  Health-Doctor
//
//  Created by 勇胡 on 2023/12/14.
//  Copyright © 2023 掌上卫健. All rights reserved.
//团队列表模型

import Foundation
import HandyJSON

class TeamModel: NSObject,HandyJSON {
    required override init(){}
    //
    public var teamId = ""
    //团队图标
    public var icon = ""
    //队长ID
    public var leaderMemberId = ""
    //类型
    public var type = ""
    //团队名称
    public var name = ""
    //医生列表
    public var memberList:[TeamMember] = []
    //机构名称
    public var jgName = ""
    //机构ID
    public var jgId = ""
    //是否已禁用
    public var enable = ""
    //成立时间
    public var establishTime = ""
    //团队描述
    public var desc = ""
    //创建者
    public var cusername = ""
    //服务包项目
    public var packList:[TeamSpkgModel] = []
    
    func mapping(mapper: HelpingMapper) {
        mapper <<<
            self.desc <-- "description"
    }
    
    public class func getTeamModelBy(detail:TeamDetailModel)->TeamModel{
        let team = TeamModel()
        team.teamId = detail.teamId
        team.icon = detail.icon
        team.leaderMemberId = detail.leaderMemberId
        team.type = detail.type
        team.name = detail.name
        team.memberList = detail.memberList
        team.jgName = detail.jgName
        team.jgId = detail.jgId
        team.packList = detail.packList
        return team
    }
    
    //获取责任人，队长
    public func getLeaderItem()->TeamMember?{
        if memberList.isEmpty || leaderMemberId.isEmpty{return nil}
        for member in memberList{
            if member.memberId == leaderMemberId{
                return member
            }
        }
        return nil
    }
    
    
    
    /// 获取团队成员
    /// - Parameter maxCount: 最多显示个数
    /// - Returns: 返回名称
    public func getMemberNames(maxCount:Int = 3)->String{
        if memberList.isEmpty{return ""}
        var membersStr = ""
        for(i,member) in memberList.enumerated(){
            if i < maxCount{
                membersStr.append("\(member.name)、")
            }
        }
        membersStr = membersStr.removeLastChart("、")
        let totalCount = memberList.count
        if totalCount > maxCount {
            membersStr += "等\(totalCount)人"
        }
        return membersStr
    }
}

